package com.urms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.urms.entity.QueryRoleCondition;
import com.urms.entity.Role;
import com.urms.mapper.RoleMapper;
import com.urms.mapper.UserRoleMapper;
import com.urms.service.RoleSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleSerivceImpl implements RoleSerivce {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private UserRoleMapper userRoleMapper;
    @Override
    public PageInfo<Role> findRole(QueryRoleCondition qrc) {
        PageHelper.startPage(qrc.getPageNum(),qrc.getPageSize());
        List<Role> list=roleMapper.selectAll();
        PageInfo<Role> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Role> selectRoleByForm(QueryRoleCondition qrc) {
        return roleMapper.selectRoleByForm(qrc);
    }

    @Override
    public Integer deleteRoleById(Integer roleId) {
        return roleMapper.deleteRoleById(roleId);
    }

    @Override
    public Integer roleUpdate(Role role) {
        return roleMapper.roleUpdate(role);
    }

    @Override
    public PageInfo<Role> roleSelectByForm(QueryRoleCondition qrc) {
        PageHelper.startPage(qrc.getPageNum(),qrc.getPageSize());
        List<Role> roles=roleMapper.roleSelectByForm(qrc);
        PageInfo<Role> pageInfo=new PageInfo<>(roles);
        return pageInfo;
    }

    @Override
    public int selectUserByRoleId(Integer roleId) {
        return userRoleMapper.selectUserByRoleId(roleId);
    }

    @Override
    public Integer deleteRoleList(Integer[] roleIds) {
        return roleMapper.deleteRoleList(roleIds);
    }

    @Override
    public Integer insertRole(Role role) {
        return roleMapper.insertRole(role);
    }
}
